#include "common.h"
#include <QDesktopServices>
#include <QUrl>
#include <QCoreApplication>
#include <QDir>
#include <QDebug>
#include <QWebEngineView>

bool openLocalHtmlFile(const QString& relativePath) {

    QString exeDir = QCoreApplication::applicationDirPath();
    QDir dir(exeDir);
    QString fullPath = dir.filePath(relativePath);
    QUrl fileUrl = QUrl::fromLocalFile(fullPath);

    // Open with the system default browser
    bool opened = QDesktopServices::openUrl(fileUrl);

    if (opened) {
        qDebug() << "Attempted to open local HTML file：" << fullPath;
    } else {
        qDebug() << "Unable to open local HTML file：" << fullPath;
    }

    return opened;
}

// Qt WebEngine
void openServerHelpPage(const QUrl& url,
                        const QSize& size = QSize(1280, 720))
{
    auto *view = new QWebEngineView;
    view->setAttribute(Qt::WA_DeleteOnClose);
    view->resize(size);
    view->load(url);
    view->show();
}
